package com.x.example.toolbar.items;

import android.content.Context;
import android.graphics.drawable.GradientDrawable;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.x.example.R;
import com.example.uiframework.utils.Utils;
import com.x.uikit.toolbar.XToolbar;
import com.x.uikit.toolbar.XToolbarItem;


public class CommentItem extends XToolbarItem {
    LinearLayout mContainer;

    public CommentItem(@NonNull Context context, @NonNull String token) {
        super(context, token);
        mContainer = new LinearLayout(getContext());
        GradientDrawable bgDrawable = new GradientDrawable();
        bgDrawable.setCornerRadius(Utils.res.dpI(16));
        bgDrawable.setColor(0xfff0f0f0);
        mContainer.setBackground(bgDrawable);
        ImageView ivIcon = new ImageView(getContext());
        ivIcon.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        ivIcon.setImageResource(R.drawable.write);
        ivIcon.setAlpha(0.5f);
        LinearLayout.LayoutParams lpIcon = new LinearLayout.LayoutParams(Utils.res.dpI(15), Utils.res.dpI(15));
        lpIcon.leftMargin = Utils.res.dpI(6);
        lpIcon.gravity = Gravity.CENTER_VERTICAL;
        mContainer.addView(ivIcon, lpIcon);

        TextView tvTips = new TextView(getContext());
        tvTips.setTextColor(0xff666666);
        tvTips.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
        tvTips.setText("留下点什么吧...");
        LinearLayout.LayoutParams lpTips = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        lpTips.leftMargin = Utils.res.dpI(5);
        lpTips.gravity = Gravity.CENTER_VERTICAL;
        mContainer.addView(tvTips, lpTips);
        this.addView(mContainer, -1, Utils.res.dpI(32));
    }

    @Override
    public ViewGroup.LayoutParams getLayoutParams() {
        XToolbar.LayoutParams lp = new XToolbar.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT);
        lp.weight = 1;
        lp.leftMargin = lp.rightMargin = Utils.res.dpI(12);
        lp.gravity = Gravity.CENTER_VERTICAL;
        return lp;
    }
}
